from media.lib.views import FileUploadFormMixin
from project.views.lib import (
    HTMXProjectSubCreateFormView,
    HTMXProjectSubUpdateFormView,
    ProjectSubDetailView,
    ProjectSubListView,
    template_path
)

from .. import models
from .. import forms

class QualityControlListView(ProjectSubListView):
    template_name = template_path("quality_control/list.html")

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        project = self.get_project()
        context["project"] = project
        context["count"] = project.qualitycontrol_set.count()
        return context

class QualityControlCreateView(
    FileUploadFormMixin,
    HTMXProjectSubCreateFormView
):
    form_class = forms.QualityControlForm
    create_view_name = "project:quality_control/create"
    detail_view_name = "project:quality_control/detail"

class QualityControlDetailView(ProjectSubDetailView):
    model = models.QualityControl
    form_class = forms.QualityControlForm
    template_name = template_path("quality_control/detail.html")

class QualityControlUpdateView(
    FileUploadFormMixin,
    HTMXProjectSubUpdateFormView
):
    model = models.QualityControl
    form_class = forms.QualityControlForm
    update_view_name = "project:quality_control/update"
    detail_view_name = "project:quality_control/detail"
